home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1989 …il & Dave's Excellent CD / Excellent CD HFS.raw / Peripherals / MacinTalk / Example Programs / SpeakFile Source / SpeakFile.p
Encoding:
Text File  |  1989-04-13  |  2.9 KB  |  96 lines  |  [TEXT/MPS ]

  1. PROGRAM SpeakFile(f);
  2.  
  3. (*   A quick and dirty program to read a file out loud.  The file must be named
  4.      "TextToSpeak" and reside on the default drive.  The program reads 5120
  5.      characters from this file and sends that string thru the Reader English to
  6.      phonetics converter.  The output from Reader is then sent thru the MacinTalk
  7.      speech synthesizer.  The input file is assumed to be terminated by a "##".
  8.      Only the SpeechOn error code is checked.  THIS PROGRAM IS INTENDED ONLY AS A
  9.      DEMONSTRATION OF HOW TO SETUP AND CALL THE SPEECH SYNTHESIZER, AND DOES
  10.      NOT CONFIRM TO MACINTOSH'S USER INPUT STYLE.                              
  11.  
  12. Here is a simple build procedure:
  13.  
  14. pascal -p {MPW}SpeakFile.p
  15. link -p -c MBAU -t APPL ∂
  16.       "{MPW}"SpeakFile.p.o ∂
  17.         "{Libraries}"Interface.o ∂
  18.         "{Libraries}"Runtime.o ∂
  19.         "{PLibraries}"Paslib.o ∂
  20.         "{Libraries}"SpeechIntf.o ∂
  21.         -o SpeakFile
  22.  
  23. This assumes:
  24.   SpeakFile.p is in {MPW}
  25.   SpeechIntf.p is in {PInterfaces}
  26.   SpeechIntf.o is in {Libraries}
  27.  
  28. *)
  29.  
  30. USES
  31.   {$LOAD PasDump.dump}
  32.   Memtypes, Quickdraw, OSIntf, ToolIntf, PackIntf, SpeechIntf;
  33.  
  34.  
  35.  
  36.  
  37. TYPE
  38.    bytes = packed array[1..5120] of char;
  39.    byteptr = ^bytes;
  40.  
  41.  
  42. VAR
  43.    i:                         INTEGER;
  44.    linein:                    bytes;         {the English text to be spoken}
  45.    lineptr:                   byteptr;       {a pointer to the text}
  46.    f:                         file;          {for input file TextToSpeak}
  47.    output:                    Handle;        {Handle to phonetic string}
  48.    theSpeech:                 SpeechHandle;  {Handle to speech globals}
  49.  
  50.  
  51. BEGIN
  52.  
  53.    i := SpeechOn('', theSpeech);             {Open the speech driver and the
  54.                                               READER English to phonetics
  55.                                               conversion package with the default
  56.                                               pronounciation ruleset.}
  57.  
  58.  
  59.    IF (i <> 0) THEN exit(SpeakFile);          {If error, go away}
  60.  
  61.  
  62.    reset(f, 'TextToSpeak');                  {Open the English input file.}
  63.  
  64.  
  65.  
  66.    i := blockread(f, linein, 10);            {Read 10 blocks (5120 chars) from
  67.                                               the input file.}
  68.  
  69.  
  70.    lineptr := @linein;                       {Setup pointer to the English text.}
  71.  
  72.  
  73.    output := NewHandle(0);                   {Create a handle for the phonetic
  74.                                               output.  Reader will dynamically
  75.                                               grow this handle as needed.}
  76.  
  77.  
  78.                {Convert the English text to phonetic codes.}
  79.  
  80.    i := Reader(theSpeech, POINTER(lineptr), 6000, output);
  81.  
  82.  
  83.    i := MacinTalk(theSpeech, output);        {Say it.}
  84.  
  85.  
  86.    SpeechOff(theSpeech);                     {Close the speech driver.}
  87.  
  88.  
  89.    DisposHandle(output);                     {Release the output handle}
  90.  
  91.  
  92.    close(f)                                  {Close the input file.}
  93.  
  94. end.
  95.  
  96.